package com.pcbly.web.components.taglib.tag;

import org.apache.struts2.util.TextProviderHelper;
import org.apache.struts2.views.jsp.ComponentTagSupport;

@SuppressWarnings("serial")
public abstract class BaseTag extends ComponentTagSupport {

	// shortcut, sets label, name, and value
	protected String key;

	protected String id;
	protected String cssClass;
	protected String cssStyle;
	protected String disabled;
	protected String name;
	protected String required;
	protected String tabindex;
	protected String value;
	protected String title;

	// HTML scripting events attributes
	protected String onclick;
	protected String ondblclick;
	protected String onmousedown;
	protected String onmouseup;
	protected String onmouseover;
	protected String onmousemove;
	protected String onmouseout;
	protected String onfocus;
	protected String onblur;
	protected String onkeypress;
	protected String onkeydown;
	protected String onkeyup;
	protected String onselect;
	protected String onchange;

	protected String getObjectValue(String obj) {
		if (obj != null && obj.startsWith("%{") && obj.endsWith("}")) {
			obj = obj.substring(2, obj.length() - 1);
			obj = String.valueOf(this.getStack().findValue(obj));
		} else {
			String tv = null;
			tv = obj;
			obj = String.valueOf(this.getStack().findValue(obj));
			if (obj == null || "".equals(obj)) {
				obj = TextProviderHelper.getText(tv, tv, this.getStack());
			}
		}
		return obj;
	}
	protected String getStringValue(String obj) {
		if (obj != null && obj.startsWith("%{") && obj.endsWith("}")) {
			obj = obj.substring(2, obj.length() - 1);
			obj = String.valueOf(this.getStack().findValue(obj));
		}
		return obj;
	}
	private void setStack() {
		key=getObjectValue(key);
		id=getStringValue(id);
		cssClass=getStringValue(cssClass);
		cssStyle=getStringValue(cssStyle);
		disabled=getStringValue(disabled);
		name=getStringValue(name);
		required=getStringValue(required);
		tabindex=getStringValue(tabindex);
		value=getObjectValue(value);
		title=getObjectValue(title);

		// HTML scripting events attributes
		onclick=getStringValue(onclick);
		ondblclick=getStringValue(ondblclick);
		onmousedown=getStringValue(onmousedown);
		onmouseup=getStringValue(onmouseup);
		onmouseover=getStringValue(onmouseover);
		onmousemove=getStringValue(onmousemove);
		onmouseout=getStringValue(onmouseout);
		onfocus=getStringValue(onfocus);
		onblur=getStringValue(onblur);
		onkeypress=getStringValue(onkeypress);
		onkeydown=getStringValue(onkeydown);
		onkeyup=getStringValue(onkeyup);
		onselect=getStringValue(onselect);
		onchange=getStringValue(onchange);
	}

	protected void populateParams() {
		super.populateParams();
		setStack();		
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getCssClass() {
		return cssClass;
	}

	public void setCssClass(String cssClass) {
		this.cssClass = cssClass;
	}

	public String getCssStyle() {
		return cssStyle;
	}

	public void setCssStyle(String cssStyle) {
		this.cssStyle = cssStyle;
	}

	public String getDisabled() {
		return disabled;
	}

	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getRequired() {
		return required;
	}

	public void setRequired(String required) {
		this.required = required;
	}

	public String getTabindex() {
		return tabindex;
	}

	public void setTabindex(String tabindex) {
		this.tabindex = tabindex;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getOnclick() {
		return onclick;
	}

	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}

	public String getOndblclick() {
		return ondblclick;
	}

	public void setOndblclick(String ondblclick) {
		this.ondblclick = ondblclick;
	}

	public String getOnmousedown() {
		return onmousedown;
	}

	public void setOnmousedown(String onmousedown) {
		this.onmousedown = onmousedown;
	}

	public String getOnmouseup() {
		return onmouseup;
	}

	public void setOnmouseup(String onmouseup) {
		this.onmouseup = onmouseup;
	}

	public String getOnmouseover() {
		return onmouseover;
	}

	public void setOnmouseover(String onmouseover) {
		this.onmouseover = onmouseover;
	}

	public String getOnmousemove() {
		return onmousemove;
	}

	public void setOnmousemove(String onmousemove) {
		this.onmousemove = onmousemove;
	}

	public String getOnmouseout() {
		return onmouseout;
	}

	public void setOnmouseout(String onmouseout) {
		this.onmouseout = onmouseout;
	}

	public String getOnfocus() {
		return onfocus;
	}

	public void setOnfocus(String onfocus) {
		this.onfocus = onfocus;
	}

	public String getOnblur() {
		return onblur;
	}

	public void setOnblur(String onblur) {
		this.onblur = onblur;
	}

	public String getOnkeypress() {
		return onkeypress;
	}

	public void setOnkeypress(String onkeypress) {
		this.onkeypress = onkeypress;
	}

	public String getOnkeydown() {
		return onkeydown;
	}

	public void setOnkeydown(String onkeydown) {
		this.onkeydown = onkeydown;
	}

	public String getOnkeyup() {
		return onkeyup;
	}

	public void setOnkeyup(String onkeyup) {
		this.onkeyup = onkeyup;
	}

	public String getOnselect() {
		return onselect;
	}

	public void setOnselect(String onselect) {
		this.onselect = onselect;
	}

	public String getOnchange() {
		return onchange;
	}

	public void setOnchange(String onchange) {
		this.onchange = onchange;
	}

}
